<?php
	class Commodities extends CI_Controller{
		var $userinfo;
		function Commodities(){
			parent::__construct();
			//$this->load->database();
			$this->load->model('commodity_model');
			
			$this->userinfo = $this->session->userdata('UserInfo');
			
		}
		
		function index(){
			$category=0; $commodity=0; $type=0;
			$data['category'] = $this->commodity_model->SelectCommodityCategory();
			$data['userinfo'] = $this->userinfo;
			
			if($this->input->post('kategori'))
			{
				$category = $this->input->post('kategori');
				$data['commodityname'] = $this->commodity_model->SelectCommodityName($category);
			}
			
			if($this->input->post('komoditas'))
			{
				$commodity = $this->input->post('komoditas');
				$data['commoditytype'] = $this->commodity_model->SelectCommodityType($commodity);
			}
			
			if($this->input->post('jenis'))
			{
				$type = $this->input->post('jenis');
			}
			
			$data['formvalue'] = array(
				'kategori'=>$category,
				'komoditas'=>$commodity,
				'jenis'=>$type
			);
			
			$data['commodity'] = $this->commodity_model->SelectCommodity($this->userinfo['UserId'],$category,$commodity,$type);
			
			$this->mytemplate->dressing_secure('commodities/seller_commodity',$data);
		}

        function commodity_receipt(){
                        $data['category'] = $this->commodity_model->SelectCommodityCategory();
                        $data['commodity'] = $this->commodity_model->SelectCommodity(1,0,0,0);
                        //$data['submenu'] = $this->mytemplate->getsecuresubmenu($userinfo['UserId'], 3);
                        $this->mytemplate->dressing_secure('commodities/seller_commodity_receipt',$data);
        }

                function seller_transaction() {
                        $this->mytemplate->dressing_secure('commodities/seller_transaction',NULL);
                }

                function seller_auction(){
                        $data['category'] = $this->commodity_model->SelectCommodityCategory();
                        $data['commodity'] = $this->commodity_model->SelectCommodity(1,0,0,0);
                        $this->mytemplate->dressing_secure('commodities/seller_auction',NULL);
                }

                function buyer_auction(){
                        $this->mytemplate->dressing_secure('commodities/buyer_auction',NULL);
                }

                function buyer_transaction(){
                        $this->mytemplate->dressing_secure('commodities/buyer_transaction',NULL);
                }

                function viewsellercommodity()
				{
					$data['query'] = $this->modeldata->getCommodity();
					$this->load->view('pages/seller_commodity', $data);
				}
		
				/*pop up methods*/
				function commodity_add()
				{
					$data['category'] = $this->commodity_model->SelectCommodityCategory();
					$data['province'] = $this->admin_model->SelectProvince(0);
					$data['uom'] = $this->commodity_model->SelectUOM(0);
					$this->mytemplate->dressing_secure_popup('Tambah Komoditi', 'commodities/popup/commodity_add',$data);
				}
				
				function getcommodityname($category){
					echo json_encode($this->commodity_model->SelectCommodityName($category));
				}				
	}
?>
